home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / stencil / gameOfLife.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  104 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  * gameOfLife.c:
  19.  *
  20.  * Here is a program that plays the game of life by using stencil planes.
  21.  * The gl window does not watch for REDRAW events so if one pops/pushes 
  22.  * other * windows on to/off of this window, the game becomes a bit more
  23.  * interesting...
  24.  */
  25. #include <gl.h>
  26. #include <device.h>
  27.  
  28. #define DX 800
  29. #define DY 800
  30. #define DEADCOLOR 0
  31. #define LIVECOLOR 0xffffffff
  32.  
  33. long xorg, yorg;
  34.  
  35. unsigned long pixbuf[DX][DY];
  36.  
  37. main()
  38. {
  39.     long i, j;
  40.  
  41.     if (getgdesc(GD_BITS_STENCIL) < 4) {
  42.         printf("requires 4 bits of stencil planes to run\n");
  43.         return;
  44.     }
  45.     prefsize(DX, DY);
  46.     winopen("game of life using stencil planes");
  47.     subpixel(TRUE);
  48.     getorigin(&xorg, &yorg);
  49.     stensize(4);
  50.     RGBmode();
  51.     gconfig();
  52.     zbuffer(TRUE);
  53.     czclear(0, 0);
  54.     zwritemask(0);
  55.     zfunction(ZF_NOTEQUAL);
  56.     sclear(0);
  57.     zbuffer(FALSE);
  58.     for (i = 0; i < DX; i++)
  59.         for (j = 0; j < DY; j++) pixbuf[i][j] = DEADCOLOR;
  60.     for (i = 40; i < DX-40; i++) pixbuf[DY/2][i] = LIVECOLOR;
  61.     lrectwrite(0, 0, DX-1, DY-1, (unsigned long *)pixbuf);
  62.     readsource(SRC_FRONT);
  63.     while(1) {
  64.         iteratelife();
  65.     }
  66. }
  67.  
  68. readpix()
  69. {
  70.     lrectread(0, 0, DX-1, DY-1, (unsigned long *)pixbuf);
  71. }
  72.  
  73. writepix(long dx, long dy)
  74. {
  75.     lrectwrite(dx, dy, dx+DX-1, dy+DY-1, (unsigned long *)pixbuf);
  76. }
  77.  
  78. iteratelife()
  79. {
  80.  
  81.     readpix();
  82.     wmpack(0);
  83.     pixmode(PM_ZDATA, 1.0);
  84.     zbuffer(TRUE);
  85.     stencil(TRUE, 1, SF_ALWAYS, 0xf, ST_KEEP, ST_KEEP, ST_INCR);
  86.     writepix(-1, -1);
  87.     writepix(-1, 0);
  88.     writepix(-1, 1);
  89.     writepix(0, -1);
  90.     writepix(0, 1);
  91.     writepix(1, -1);
  92.     writepix(1, 0);
  93.     writepix(1, 1);
  94.     zbuffer(FALSE);
  95.     pixmode(PM_ZDATA, 0.0);
  96.     wmpack(0xffffffff);
  97.     cpack(LIVECOLOR);
  98.     stencil(TRUE, 3, SF_EQUAL, 0xf, ST_KEEP, ST_DECR, ST_DECR);
  99.     rectfi(0, 0, 10000, 10000);
  100.     stencil(TRUE, 2, SF_NOTEQUAL, 0xf, ST_ZERO, ST_ZERO, ST_ZERO);
  101.     cpack(DEADCOLOR);
  102.     rectfi(0, 0, 10000, 10000);
  103. }
  104.